package resource.handler;

import java.util.HashMap;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * Parser SAX
 * @author PQMY07891
 *
 */
public class MusicHandler extends DefaultHandler {

	private HashMap<String, String> l_m;
	public MusicHandler(HashMap<String, String> s){
		l_m = s;
	}

	public void characters(char[] buffer, int start, int length) {
	}

	public void startElement(String uri, String name, String qName, Attributes attributes){
		if (qName.equals("music")){
				l_m.put(attributes.getValue("name"),attributes.getValue("url"));
		};
	}

	// When the parser encounters the end of an element, it calls this method
	public void endElement(String uri, String name, String qName){
		
	}

	/** This method is called when warnings occur */
	public void warning(SAXParseException exception) {
		System.err.println("WARNING: line " + exception.getLineNumber() + ": "
				+ exception.getMessage());
	}

	/** This method is called when errors occur */
	public void error(SAXParseException exception) {
		System.err.println("ERROR: line " + exception.getLineNumber() + ": "
				+ exception.getMessage());
	}

	/** This method is called when non-recoverable errors occur. */
	public void fatalError(SAXParseException exception) throws SAXException {
		System.err.println("FATAL: line " + exception.getLineNumber() + ": "
				+ exception.getMessage());
		throw (exception);
	}
}